package com.example.mqtt.service.Imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mqtt.cache.RowingCache;
import com.example.mqtt.entity.Rowing;
import com.example.mqtt.mapper.RowingMapper;
import com.example.mqtt.service.RowingService;
import org.springframework.stereotype.Service;

@Service
public class RowingServiceImp extends ServiceImpl<RowingMapper, Rowing> implements RowingService {

    private final RowingMapper mapper;

    public RowingServiceImp(RowingMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Rowing getRowingById(String rowingId) {
        Rowing rowing = RowingCache.get(rowingId);
        if (rowing == null) {
            rowing = mapper.selectById(rowingId);
            if (rowing != null) {
                RowingCache.put(rowingId, rowing);
            }
        }
        return rowing;
    }

    @Override
    public String getRowingNo(String rowingId) {
        String rowingNo = "";
        Rowing rowingById = getRowingById(rowingId);
        if (rowingById != null) {
            rowingNo = rowingById.getRowingNo();
        }
        return rowingNo;
    }
}
